package com.chao.yyks.util;


import com.alibaba.fastjson.JSONObject;
import com.chao.common.util.AddressConstant;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 系统初始化数据
 */
@Component
public class CommonData implements CommandLineRunner {

    @Value("classpath:address.json")
    private Resource address;

    @Override
    public void run(String... args) throws Exception {
        try {
            String areaData = IOUtils.toString(address.getInputStream(), StandardCharsets.UTF_8);
            AddressConstant.setAddress(JSONObject.parseObject(areaData));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
